package cn.iocoder.yudao.module.eval.dal.mysql.assignment;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.eval.controller.admin.assignment.vo.EvalPersonnelAssignmentPageReqVO;
import cn.iocoder.yudao.module.eval.dal.dataobject.assignment.EvalPersonnelAssignmentDO;
import org.apache.ibatis.annotations.Mapper;

import java.util.Collection;
import java.util.List;

/**
 * 人员分配 Mapper
 *
 * @author 芋道源码
 */
@Mapper
public interface EvalPersonnelAssignmentMapper extends BaseMapperX<EvalPersonnelAssignmentDO> {

    default PageResult<EvalPersonnelAssignmentDO> selectPage(EvalPersonnelAssignmentPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<EvalPersonnelAssignmentDO>()
                .eqIfPresent(EvalPersonnelAssignmentDO::getPlanId, reqVO.getPlanId())
                .eqIfPresent(EvalPersonnelAssignmentDO::getUserId, reqVO.getUserId())
                .eqIfPresent(EvalPersonnelAssignmentDO::getPersonType, reqVO.getPersonType())
                .eqIfPresent(EvalPersonnelAssignmentDO::getSubjectId, reqVO.getSubjectId())
                .eqIfPresent(EvalPersonnelAssignmentDO::getAssignmentStatus, reqVO.getAssignmentStatus())
                .eqIfPresent(EvalPersonnelAssignmentDO::getConfirmStatus, reqVO.getConfirmStatus())
                .betweenIfPresent(EvalPersonnelAssignmentDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(EvalPersonnelAssignmentDO::getId));
    }

    default List<EvalPersonnelAssignmentDO> selectListByPlanId(Long planId) {
        return selectList(EvalPersonnelAssignmentDO::getPlanId, planId);
    }

    default List<EvalPersonnelAssignmentDO> selectListByPlanIdAndPersonType(Long planId, Integer personType) {
        return selectList(new LambdaQueryWrapperX<EvalPersonnelAssignmentDO>()
                .eq(EvalPersonnelAssignmentDO::getPlanId, planId)
                .eq(EvalPersonnelAssignmentDO::getPersonType, personType));
    }

    default List<EvalPersonnelAssignmentDO> selectListByUserId(Long userId) {
        return selectList(EvalPersonnelAssignmentDO::getUserId, userId);
    }

    default List<EvalPersonnelAssignmentDO> selectListByUserIds(Collection<Long> userIds) {
        return selectList(new LambdaQueryWrapperX<EvalPersonnelAssignmentDO>()
                .in(EvalPersonnelAssignmentDO::getUserId, userIds));
    }

    default List<EvalPersonnelAssignmentDO> selectListBySubjectId(Long subjectId) {
        return selectList(EvalPersonnelAssignmentDO::getSubjectId, subjectId);
    }

    default List<EvalPersonnelAssignmentDO> selectListByAssignmentStatus(Integer assignmentStatus) {
        return selectList(EvalPersonnelAssignmentDO::getAssignmentStatus, assignmentStatus);
    }

    default EvalPersonnelAssignmentDO selectByPlanIdAndUserId(Long planId, Long userId) {
        return selectOne(new LambdaQueryWrapperX<EvalPersonnelAssignmentDO>()
                .eq(EvalPersonnelAssignmentDO::getPlanId, planId)
                .eq(EvalPersonnelAssignmentDO::getUserId, userId));
    }

}
